// pages/my/address/address.js
Page({
  data: {
    name: "",
    moblile: "",
    address: ""
  },
  onLoad: function (options) {},
  submit() {
    if (!this.data.name) {
      getApp().globalData.vant.toast("请填写姓名");
    } else if (!this.data.moblile) {
      getApp().globalData.vant.toast("请填写手机号");
    } else if (!getApp().globalData.reg.tel.test(this.data.moblile)) {
      getApp().globalData.vant.toast("请填写正确的手机号");
    } else if (!this.data.address) {
      getApp().globalData.vant.toast("请填写收货地址");
    } else {
      getApp().globalData.vant.dialog.confirm({
          title: "确定兑换吗?",
          message: "兑换成功，将在统-发货日送货上门，请保持电话畅通!",
          showCancelButton: false,
          confirmButtonText: "确定",
          confirmButtonColor: "#33B868"
        })
        .then(() => {
          getApp().globalData.http.exchangeGood({
            name: this.data.name,
            moblile: this.data.moblile,
            address: this.data.address,
          }).then(res => {
            getApp().globalData.vant.toast({
              message: "兑换成功",
              onClose: () => {
                wx.navigateTo({
                  url: "/pages/my/exchangerecord/exchangerecord",
                });
              }
            });
          }).catch(e => {
            getApp().globalData.vant.toast(e.msg);
          });
        });
    }
  }
})